package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.StoredValueActivity;
import com.yfp.operation.domain.dto.StoredValueActivityDTO;
import com.yfp.operation.service.StoredValueActivityService;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @version 1.0
 * @date 2024-11-22 10:21
 */
@RestController
@RequestMapping("/stored")
@Tag(name = "储值活动")
public class StoredValueActivityController extends BaseController {


    @Resource
    private StoredValueActivityService storedValueActivityService;


    /**
     * 储值活动列表
     * @param storedValueActivityDTO
     * @return
     */
    @GetMapping
    @Operation(summary = "储值活动列表")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = StoredValueActivity.class)))})
    public TableDataInfo activityList(StoredValueActivityDTO storedValueActivityDTO) {
        startPage();
        TableDataInfo dataTable = getDataTable(storedValueActivityService.activityList(storedValueActivityDTO));
        return dataTable;
    }


    /**
     * 新增储值活动列表
     * @param storedValueActivity
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "新增储值活动列表")
    public R<?> add(@RequestBody StoredValueActivity storedValueActivity) {
        return storedValueActivityService.add(storedValueActivity);
    }


    @GetMapping("/{activityId}")
    @Operation(summary = "储值活动详情")
    public R<StoredValueActivity> particulars(@PathVariable Long activityId) {
        StoredValueActivity storedValueActivity = storedValueActivityService.particulars(activityId);
        return R.ok(storedValueActivity);
    }


    @PutMapping("/updateStatus")
    @Operation(summary = "修改活动状态")
    public R<?> updateStatus(@RequestParam("id") Long id, @RequestParam("status") @ApiParam(value = "状态 2失效 0删除") Integer status){
        storedValueActivityService.updateStatus(id,status);
        return R.ok();
    }


    @PutMapping("/expire")
    @Operation(summary = "储值活动到期失效")
    public R<Void> storedActivityExpire(){
        storedValueActivityService.storedActivityExpire();
        return R.ok();
    }


}
